# -*- coding: UTF-8 -*-
# Author: Antoni Aloy - apsl.net
# 
from django.db import models
from django.conf import settings
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _


class BlogrollManager(models.Manager):
    def current_active(self):
        ''' A QuerySet of all active blogroll records '''
        return self.filter(visible=True)
    

class Blogroll(models.Model):
    """Blogroll mantain the list of blogs we want to link from our blog"""
    objects = BlogrollManager()    
    name = models.CharField(_(u'name'), max_length=80)
    description = models.TextField(_(u"Blog description"))
    slug = models.SlugField(_('slugfield'),  max_length=120, help_text=_(u"Slug is the same as name, but url friendly"))
    visible = models.BooleanField(_(u"visible"), default=True, help_text=_(u"Is blog viewable on site?"))
    url = models.URLField(_(u"URL"))
    user = models.ForeignKey(User, default=settings.DEFAULT_BLOG_USER, related_name=u"user_blogs")
    def __unicode__(self):
        return self.url
    def get_absolute_url(self):
        return self.url
    class Meta:
        ordering = ['name']
        verbose_name_plural = "Blogs"    


class LinkManager(models.Manager):
    "Manager to show just the active records"
    def current_active(self):
        ''' A QuerySet of all active blogroll records '''
        return self.filter(visible=True)

class Link(models.Model):
    """Direct links to articles, other blogs articles, etc."""
    objects = LinkManager()    
    name = models.CharField(_(u"Link name"), max_length=100)
    url = models.URLField()
    slug = models.SlugField( max_length=220, help_text=_("url slug form"))
    visible = models.BooleanField(_(u"visible"), default=True, help_text=_(u"Is link viewable on site?"))
    user = models.ForeignKey(User, default=settings.DEFAULT_BLOG_USER, related_name=u"user_links")

    class Meta:
        ordering = ['name']
        verbose_name_plural = "links"
    def __unicode__(self):
        return self.name
    def get_absolute_url(self):
        return self.url


